home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Mac OS USB DDK_v1.0.1 / Examples / MouseModule / MouseConfigParse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  2.0 KB  |  60 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ConfigParse.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <processes.h>
  15. #include <DriverServices.h>
  16. #include <USB.h>
  17.  
  18.  
  19. #include "MouseModule.h"
  20.  
  21. OSErr FindHIDInterfaceByNumber(LogicalAddress pConfigDesc, UInt32 ReqInterface, USBInterfaceDescriptorPtr * hInterfaceDesc)
  22. {
  23. UInt32 totalLength;
  24. void * pEndOfDescriptors;
  25. USBInterfaceDescriptorPtr     pMyIntDesc;
  26. USBDescriptorHeaderPtr        pCurrentDesc;
  27. unsigned long                anAddress, anOffset;
  28.  
  29.     totalLength = USBToHostWord(((USBConfigurationDescriptorPtr)pConfigDesc)->totalLength);
  30.     pEndOfDescriptors = (Ptr)pConfigDesc + totalLength;                    // get the total length and add it to the start of the config space
  31.     pCurrentDesc = (USBDescriptorHeaderPtr)pConfigDesc;                    // point the currentdesc to the start of the config space
  32.     
  33.     while (pCurrentDesc < pEndOfDescriptors)                            // as long as we haven't exhausted all the descriptors
  34.     {
  35.         if (pCurrentDesc->descriptorType == kUSBInterfaceDesc)            // look at the current descriptor
  36.         {
  37.             pMyIntDesc = (USBInterfaceDescriptorPtr)pCurrentDesc;        // if it's an interface descriptor
  38.             if ((pMyIntDesc->interfaceClass == kUSBHIDInterfaceClass) &&
  39.                 (pMyIntDesc->interfaceNumber == ReqInterface))            // and if it's the interface we want...
  40.             {
  41.                 *hInterfaceDesc = pMyIntDesc;                            // if it is, then return with hInterfaceDesc set to the
  42.                 return noErr;                                            // current descriptor pointer
  43.             }
  44.         }
  45.         // (Ptr)pCurrentDesc += pCurrentDesc->length;                    // Nope, that either wasn't an interface descriptor
  46.         anAddress = (unsigned long) pCurrentDesc;                        // Nope, that either wasn't an interface descriptor
  47.         anOffset  = (unsigned long) pCurrentDesc->length;
  48.         anAddress += anOffset;
  49.         pCurrentDesc = (USBDescriptorHeaderPtr) anAddress;
  50.         if (pCurrentDesc->length == 0)
  51.             break;
  52.     }                                                                    // or it was, but not the droid we're looking for.
  53.     *hInterfaceDesc = NULL;
  54.     return kUSBInternalErr;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.